<?php
defined('BASEPATH') OR exit('No direct script access allowed');
//配置管理
class Config extends CommonController {

	function __construct(){
		
		parent::__construct();
		$this->load->model('Index/ConfigModel','CurModel');
		
	}
	
	
	//start
	/**
	* @name 获取列表
	* @return 成功返回array
	*/
	//end
	function get_list(){
		
		$list = $this->CurModel->getAll();
		
		$farr = array('sys_name','zone_time','sys_logo','max_money','sys_status','reason');
		
		foreach($list as $key=>$val){
			if(empty($val['title'])){
				$list[$key]['title'] = $val['name'];
			}
			
		}
		
		$this->data_out($list);
	}
	
	//start
	/**
	* @name 获取列表
	* @return 成功返回array
	*/
	//end
	function get_info(){
		
		$list = $this->CurModel->getAll();
		
		$farr = array('sys_name','zone_time','sys_logo','max_money','sys_status','reason');
		
		$info = array();
		foreach($farr as $kk){
			$info[$kk] = '';
			
			foreach($list as $key=>$val){
				if($val['name']==$kk){
					$info[$kk] = $val['value'];
					break;
				}
			}
		}
		
		
		
		$this->data_out($info);
	}
	
	//start
	/**
	* @name 保存
	* @param info 
	* @return 成功返回array
	*/
	//end
	function save(){
		
		$info = $this->input->post('info',null,array());
		$farr = array('sys_name','zone_time','sys_logo','max_money','sys_status','reason');
		foreach($info as $key=>$val){
			if(in_array($key,$farr)){
				$is_exist = $this->CurModel->_where_exist(array('name'=>$key));
				if($is_exist){
					$this->CurModel->edit(array('value'=>$val),"name='{$key}'");
				}
				else{
					$this->CurModel->add(array('value'=>$val,"name"=>$key));
				}
				
			}
			
		}

		$this->add_log("修改配置项",'config');
		$this->data_out(1);
	}
	
	//获取系统允许的最大金额
	function getOneByName(){
		$name = $this->input->post('name');
		$result = $this->CurModel->get_config($name);
		$this->data_out($result);
	}
}
